package com.knightboy.smartshoes.myUi;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.Window;
import android.widget.Toast;

import com.knightboy.smartshoes.R;
import com.knightboy.smartshoes.coreUtil.DataHelper;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        // 判断设备是否支持BLE
        if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
            Toast.makeText(this, "本设备不支持BLE", Toast.LENGTH_SHORT).show();
            finish();
        }

        //核心数据类初始化
        DataHelper.init();

//        //蓝牙服务不存在时，启动service
//        if(hasServiceForName("com.knightboy.smartshoes.blueTooth.BlueToothLeService") == false){
//            Intent intent = new Intent(this, BlueToothLeService.class);
//            this.startService(intent);
//        }

        //设置跳转
        final Intent intent = new Intent();
        intent.setClass(MainActivity.this, FirstActivity.class);

        //创建定时器
        Timer timer = new Timer();

        //创建定时任务
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                startActivity(intent);
                finish();
            }
        };
        //定时
        timer.schedule(task, 2000);
    }

//    public boolean hasServiceForName(String serviceName){
//        //返回的结果
//        boolean result = false;
//        //根据服务名字判断是否存在
//        ActivityManager myManager=(ActivityManager)MainActivity.this.getSystemService(Context.ACTIVITY_SERVICE);
//        ArrayList<ActivityManager.RunningServiceInfo> runningService = (ArrayList<ActivityManager.RunningServiceInfo>) myManager.getRunningServices(30);
//        for(int i = 0 ; i<runningService.size();i++)
//        {
//            if(runningService.get(i).service.getClassName().toString().equals(serviceName))
//            {
//                //找到符合的服务就返回真
//                result = true;
//            }
//        }
//        return result;
//    }
}
